#include <random.h>
#include <user.h>
#include <timer.h>
#include <defs.h>

void RandomServer() {
  random_req msg;
  int reply = 1;
  
  int sender_tid;
  for ( ; ; ) {
    Receive(&sender_tid, (char*)&msg, sizeof(random_req));
    if (msg.type == RAND_MSG) {
      reply = reply * 1103515245 + 12345;
      Reply(sender_tid, (char*)&reply, sizeof(int));
    } else if (msg.type == SRAND_MSG) {
      reply = msg.seed;
      Reply(sender_tid, NULL, 0);
    } else {
      // TODO: return some kind of error
    }
  }
  Exit();
}
